package cn.lyvust.shili03;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

/**
 * Description:
 * date: 2021-5-25 20:18
 *
 * @author Guo_guo
 * @since JDK 1.8
 */
public class TestDb {
    public static void main(String[] args) {
        Connection conn = null;
        String url = "jdbc:mysql://localhost:3306/student?user=root&password=123456";
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection(url);
            String sql = "insert into tusers(username,password) values(?,?)";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            for (int i = 0; i < 10; i++) {
                pstmt.setString(1, "tom" + i);
                pstmt.setString(2, "123456");
                pstmt.addBatch();
            }
            pstmt.executeBatch();
            conn.close();
        } catch (Exception e) {
            System.out.println("代码或数据库异常" + e);
        }
    }
}
